package ${obj.getPackage()};

import cool.mtc.minghe.service.service.BaseServiceImpl;
import cool.mtc.core.page.PageData;
import ${obj.entityBasePackage}.${obj.relativePackage}.${obj.classPrefix}DO;
import ${obj.modelBasePackage}.${obj.relativePackage}.form.*;
import ${obj.modelBasePackage}.${obj.relativePackage}.query.*;
import ${obj.modelBasePackage}.${obj.relativePackage}.dto.*;
import ${obj.daoBasePackage}.${obj.relativePackage}.${obj.classPrefix}Mapper;
import ${obj.serviceBasePackage}.${obj.relativePackage}.${obj.classPrefix}Service;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author ${obj.author!'Code Generator'}
 */
@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class ${obj.getClassName()} extends BaseServiceImpl implements ${obj.classPrefix}Service {
    private final ${obj.classPrefix}Mapper ${obj.objectPrefix}Mapper;

    @Override
    @Transactional
    public long insert(${obj.classPrefix}Form form) {
        ${obj.classPrefix}DO ${obj.objectPrefix}DO = form.transToDO();
        ${obj.objectPrefix}Mapper.insert(${obj.objectPrefix}DO);
        return ${obj.objectPrefix}DO.getId();
    }

    @Override
    @Transactional
    public void update(${obj.classPrefix}Form form) {
        ${obj.classPrefix}DO ${obj.objectPrefix}DO = ${obj.objectPrefix}Mapper.selectById(form.getId());
        form.updateDO(${obj.objectPrefix}DO);
        ${obj.objectPrefix}Mapper.updateById(${obj.objectPrefix}DO);
    }

    @Override
    @Transactional
    public void delete(Long id) {
        if (null == id) {
            return;
        }
        ${obj.classPrefix}DO ${obj.objectPrefix}DO = ${obj.objectPrefix}Mapper.selectById(id);
        if (null == ${obj.objectPrefix}DO) {
            return;
        }
        this.handleCheckCanDelete(${obj.objectPrefix}DO);
        ${obj.objectPrefix}Mapper.deleteById(id);
    }

    /**
     * 检查是否可以删除
     */
    private void handleCheckCanDelete(${obj.classPrefix}DO ${obj.objectPrefix}DO) {
        // TODO 检查是否可以删除
    }

    @Override
    public PageData${r'<'}${obj.classPrefix}ListDTO${r'>'} pageList(${obj.classPrefix}Query query) {
        return null;
    }

    @Override
    public ${obj.classPrefix}DTO info(Long id) {
        if (null == id) {
            return null;
        }
        return null;
    }
}
